package enum_test;

public enum FlightType {

	OW(1, "单程"), RT(2, "往返");
	public Integer code;
	public String desc;

	private FlightType(Integer code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public static FlightType getTypeByCode(Integer code) {
		FlightType defaultFlightType = FlightType.OW;
		for (FlightType fType : FlightType.values()) {
			if (fType.code == code) {
				return fType;
			}
		}
		return defaultFlightType;
	}

	public static String getDescByCode(Integer code) {
		return getTypeByCode(code).desc;

	}
}
